/*******************************************************************************
 * -------
 *   Copyright 2011 @ Fluid India Consultancy
 *   All Rights Reserved
 * -------
 ******************************************************************************/
package org.fluidindia.security.service.impl;

import org.fluidindia.security.dao.impl.UserDao;
import org.fluidindia.security.domain.User;
import org.fluidindia.security.service.ISecurityService;
import org.fluidindia.security.vo.LoginVO;
import org.springframework.beans.factory.annotation.Autowired;

import com.kapil.framework.crypto.UniqueTokenGenerator;

public class SecurityServiceImpl implements ISecurityService
{
    @Autowired
    private UserDao userDao;



    /**
     * @see ISecurityService#login(String, String)
     * 
     */
    public LoginVO login(String username, String password)
    {
        User user = this.userDao.getUser(username, password);

        LoginVO loginResponse = new LoginVO();
        loginResponse.setStatus(LoginVO.SUCCESS);

        if (user == null)
        {
            loginResponse.setStatus(LoginVO.FAIL);
        }
        else
        {
            if (user.getId() == null)
            {
                loginResponse.setStatus(LoginVO.FAIL);
            }
        }
        
        if (loginResponse.getStatus() == LoginVO.SUCCESS)
        {
            loginResponse.setUserToken(UniqueTokenGenerator.getUniqueToken());
        }
        
        return loginResponse;
    }



    public void logout(String userToken)
    {
        // TODO Auto-generated method stub
        
    }



    public void getUserPermissions(String userToken)
    {
        // TODO Auto-generated method stub
        
    }



    public Boolean hasPermission(String userToken, String artifactId, String permission)
    {
        // TODO Auto-generated method stub
        return null;
    }



    public void getRoles()
    {
        // TODO Auto-generated method stub
        
    }



    public void getArtifacts(String category)
    {
        // TODO Auto-generated method stub
        
    }
}
